#include "one.h"

#include "two.h"
#include "widget.h"
#include<QMessageBox>

One::One(QWidget *parent) :
    QWidget(parent)
{
    /* 设置位置与大小 */
    this->setGeometry(0, 0, 800, 480);

    /* 实例化及设置位置与大小，下同 */
    fWidget = new QWidget(this);
    fWidget->setGeometry(250, 130, 300, 200);

    userLineEdit = new QLineEdit();
    passwordLineEdit = new QLineEdit();

    formLayout = new QFormLayout();

    /* 实例化两个按钮对象，并设置其显示文本为登录,注册*/
    pushButton1 = new QPushButton("登录", this);
    pushButton2 = new QPushButton("退出", this);

    /* 设定两个 QPushButton 对象的位置 */
    pushButton1->setGeometry(330,250,60,40);
    pushButton2->setGeometry(450,250,60,40);

    /* 信号槽连接 */
    connect(pushButton1, SIGNAL(clicked()), this,SLOT(pushButton1_Clicked()));
    connect(pushButton2, SIGNAL(clicked()), this,SLOT(pushButton2_Clicked()));

    /* 添加行 */
    formLayout->addRow("用户名：", userLineEdit);
    formLayout->addRow("密  码：", passwordLineEdit);

    /* 设置水平垂直间距 */
    formLayout->setSpacing(10);

    /* 设置布局外框的宽度 */
    formLayout->setMargin(20);

    /* 将 formLayout 布局到 fWidget */
    fWidget->setLayout(formLayout);

    labelString = new QLabel(this);
    labelString->setText("智能电机管理系统欢迎您！");
    labelString->setGeometry(300, 50, 250, 20);
    QFont ft;
    ft.setPointSize(14);
    labelString->setFont(ft);
}

One::~One()
{

}

/* 槽函数的实现 */
void One::pushButton1_Clicked()
{
    if( userLineEdit->text().trimmed() == "123" && passwordLineEdit->text().trimmed() == "123")
    {
        emit display(1);
    }
    else{
        QMessageBox::warning(this,tr("Warning"),tr("user name or password error!"),QMessageBox::Yes);
        passwordLineEdit->clear();
        passwordLineEdit->setFocus();

    }
}
void One::pushButton2_Clicked()
{
    pushButton2->setText("别点我，没用！");
}
